<template>
	<view class="page" :style="themeColor">

		<view class="loading_css" v-if="isShow">
			<uv-loading-icon size="24" mode="circle" color="#4087FD" :show="true"></uv-loading-icon>
			<view>加载中</view>
		</view>
		<template v-else>
			<view class="home_title" :style="{paddingTop:(50+StatusBarRpx)+'rpx'}">
				<view class="text_text">智海马单词记忆家长训练机</view>
				<view class="text_news">
					<view class="news_text" @tap.stop="handleJumpDiy" data-type="navigateTo"
						:data-url="`/pages/main/platformMessage/platformMessage`">
						<image :src='STATIC_URL+"17.png"' mode=""></image>
						<text>消息</text>
					</view>
					<image @tap.stop="handleJumpDiy" data-type="navigateTo"
						:data-url="`/pages/main/myInformation/myInformation`" :src='userInfo.avatar' mode=""></image>
				</view>
			</view>


			<view class="yanjiang" @tap.stop="handleJumpDiy" data-type="navigateTo"
				:data-url="`/pages/index/englishSpeech/index`">
				<view class="yanjiang_img" :style="{backgroundImage: 'url(' + titleInfo.thumb + ')'}">
					<view class="yanjiang_left">
						<view class="yanjiang_left_img">
							<image :src='STATIC_URL+"19.png"' mode=""></image>
						</view>
						<view class="yanjiang_left_content">
							<view class="left_content_1">{{titleInfo.name}}</view>
							<view class="left_content_2">{{titleInfo.en}}</view>
						</view>
					</view>
					<view class="yanjiang_right">
						<image :src='titleInfo.round_image' mode=""></image>
					</view>
				</view>
			</view>

			<view class="classification_info">
				<view class="classification_item_1" :style="{backgroundImage: 'url(' + item.thumb + ')'}"
					v-for="(item, index) in navInfo" :key="index" @tap.stop="navigateItem(index)">
					<view class="classification_title">{{item.name}}</view>
					<view class="classification_tips">{{item.en}}</view>
					<image class="classification_img" :src='item.round_image' mode="aspectFill"></image>
				</view>
			</view>

			<!-- <view class="">
				<button @tap.stop="getBluetooth">连接蓝牙</button>
				<button @tap.stop="getPrint">打印</button>
			</view> -->
			<canvas style="width:206px;height:180px;" id="canvas" canvas-id="canvas"></canvas>

			<view class="page_bottom">
				<view class="bottom_left">
					<image :src='STATIC_URL+"23.png"' mode="aspectFill"></image>
					<text v-if="cityInfo">{{cityInfo}}</text>
					<text v-else>定位中</text>
				</view>
				<view class="bottom_right">
					<view class="bottom_left" @tap.stop="handleJumpDiy" data-type="navigateTo"
						:data-url="`/pages/index/vocabularyDetection/detectionDetails`">
						<image class="bottom_left_img_2" :src='STATIC_URL+"111.png"' mode="aspectFill"></image>
						<text>词汇量检测</text>
					</view>
					<view class="bottom_left" style="margin-left: 25rpx;" @tap.stop="handleJumpDiy" data-type="navigateTo"
						:data-url="`/pages/index/helpCenter/helpCenter`">
						<image class="bottom_left_img" :src='STATIC_URL+"24.png"' mode="aspectFill"></image>
						<text>帮助中心</text>
					</view>
					<view class="bottom_left" style="margin-left: 25rpx;" @tap.stop="handleJumpDiy"
						data-type="navigateTo" :data-url="`/pages/tabBar/mine/mine`">
						<image class="bottom_left_img" :src='STATIC_URL+"25.png"' mode="aspectFill"></image>
						<text>系统设置</text>
					</view>
				</view>
			</view>
		</template>

		<uv-modal width="300rpx" :showConfirmButton="true" :showCancelButton="true" :closeOnClickOverlay="false"
			confirmColor="#4087FD" ref="modal" title="提示" cancelText="退出登录" confirmText="重新定位" :content='showContent'
			align="center" :textStyle="{fontSize: 20 + 'px'}" @confirm="confirm" @cancel="Modalcancel"></uv-modal>

		<app-update ref="update" :auto="true"></app-update>
	</view>
</template>
<script>
	export default {
		components: {},

		data() {
			return {
				"bannerIndexfd2_0": 0,
				"fd1_0_c1": "",
				"userInfo": {},
				"navInfo": [], // 金刚区分类列表
				"titleInfo": {}, // 顶部分类英文演讲
				"isShow": true,
				"merger_name": "", // 省市区拼接
				"showContent": "",
				"cityInfo": "",
				content: '这是要转换为Canvas图像的文本' // 需要转换的文本
			};
		},
		computed: {
			themeColor() {
				return this.$store.getters.themeColor
			},

		},
		watch: {},
		onLoad(options) {
			// if (global.appTabBarType) this.toHomeDiy()
			if (!global.token) {
				uni.reLaunch({
					url: '/pages/tabBar/login/login'
				})
			}
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {
			if (global.token) {
				// #ifdef APP-PLUS
				this.getAddress();

				// this.getUserInformation();
				// this.getTitleInfo();
				// this.getIndexInfo();
				// #endif

				// #ifndef APP-PLUS
				this.getUserInformation();
				this.getTitleInfo();
				this.getIndexInfo();
				// #endif
			}
		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {

		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			// 打印
			getPrint() {
				let _this = this;
				if (_this.$store.state.printerStatus == 1) {
					let data = {
						"title": "智海马私人订制抗遗忘",
						"type": 1,
						"data": {
							"猫": "Cat",
							"猪": "Pig",
							"鱼": "Cat",
							"狗": "Pig",
							"老鼠": "Cat",
							"大哥": "Pig"
						}
					}
			
					_this.$printer.printContent(res => {
						console.log(res);
					}, data)
				} else {
					_this.$message.info('打印机初始化失败,请联系客服');
				}
			},
			
			
			// 获取定位
			getAddress() {
				let _this = this;
				// _this.isShow = true;
				uni.getLocation({
					type: 'gcj02',
					geocode: true,
					success: function(res) {
						// console.log(res);
						_this.merger_name = res.address.province + ',' + res.address.city + ',' + res.address
							.district;
						_this.cityInfo = res.address.city + res.address.district;
						_this.getused();
					},
					fail: function(err) {
						console.log(err);
						_this.showContent = '定位失败，请检查是否开启定位权限';
						_this.$refs.modal.open();
					}
				});
			},
			// 根据定位判断是否可以使用APP  post654b2da6b0b6d
			getused() {
				this.$api.post(global.apiUrls.post654b2da6b0b6d, {
					merger_name: this.merger_name
				}).then(res => {
					if (res.data.code == 1) {
						this.getUserInformation();
						this.getTitleInfo();
						this.getIndexInfo();
					} else if (res.data.code == 0) {
						this.showContent = res.data.msg;
						this.$refs.modal.open();
					} else if (res.data.code == -1) {
						this.showContent = res.data.msg;
						this.$refs.modal.open();
					}
				})
			},
			// 重新定位
			confirm() {
				this.$refs.modal.close();
				this.getAddress();
			},
			// 退出登录
			Modalcancel() {
				this.$refs.modal.close();
				this.$store.commit('logout');
				uni.reLaunch({
					url: '/pages/tabBar/login/login'
				})
			},



			navigateItem(index) {
				if (index == 0) {
					uni.navigateTo({
						url: '/pages/index/recite/index'
					})
				} else if (index == 1) {
					uni.navigateTo({
						url: '/pages/index/watchVideo/index'
					})
				} else if (index == 2) {
					uni.navigateTo({
						url: '/pages/index/antiForget/index'
					})
				} else if (index == 3) {
					uni.navigateTo({
						url: '/pages/index/breakBarrier/index'
					})
				}
			},
			// 获取首页头部
			getTitleInfo() {
				this.$api.post(global.apiUrls.post641e5f0526964, {
					type: 2
				}).then(res => {
					// console.log(res);
					this.isShow = false;
					if (res.data.code == 1) {
						this.titleInfo = res.data.data[0];
					} else {
						this.$message.info(res.data.msg);
					}
				})
			},
			// 获取首页金刚区数据  post641e5f0526964
			getIndexInfo() {
				this.$api.post(global.apiUrls.post641e5f0526964, {
					type: 1
				}).then(res => {
					this.isShow = false;
					if (res.data.code == 1) {
						this.navInfo = res.data.data;
					} else {
						this.$message.info(res.data.msg);
					}
				})
			},

			//获取用户详细信息
			async getUserInformation() {
				//请求方法
				//数据验证

				let datauserInfo = await this.$api.post(global.apiUrls.post5c78c4772da97, {

				});

				if (datauserInfo.data.code != 1) {
					this.$message.info(datauserInfo.data.msg);
					return
				}
				let infouserInfo = datauserInfo.data;
				this.userInfo = infouserInfo.data;
			},
		}
	};
</script>
<style lang="scss" scoped>
	.page_bottom {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 50rpx 25rpx;
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;

		.bottom_left {
			display: flex;
			align-items: center;
			justify-content: space-between;
			background: #FFFFFF;
			font-size: 18rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			color: #333333;
			border-radius: 20rpx;
			padding: 8rpx 15rpx;

			image {
				width: 16rpx;
				height: 18rpx;
				margin-right: 4rpx;
			}

			.bottom_left_img {
				width: 18rpx;
				height: 18rpx;
			}
			.bottom_left_img_2 {
				width: 24rpx;
				height: 24rpx;
			}
		}

		.bottom_right {
			display: flex;
			align-items: center;
		}
	}

	.classification_info {
		padding: 0 25rpx;
		display: flex;
		flex-wrap: wrap;
		justify-self: flex-start;
		justify-content: space-between;

		.classification_item_1 {
			width: 338rpx;
			height: 281rpx;
			border-radius: 16rpx;
			// background: url(/static/images/55.png) no-repeat;
			background-repeat: no-repeat;
			background-size: 100% 100%;
			margin-top: 25rpx;
			padding: 36rpx 25rpx 0 25rpx;
		}

		.classification_item_2 {
			width: 338rpx;
			height: 281rpx;
			border-radius: 16rpx;
			background: url(/static/images/56.png) no-repeat;
			background-size: 100% 100%;
			margin-top: 25rpx;
			padding: 36rpx 25rpx 0 25rpx;
		}

		.classification_item_3 {
			width: 338rpx;
			height: 281rpx;
			border-radius: 16rpx;
			background: url(/static/images/57.png) no-repeat;
			background-size: 100% 100%;
			margin-top: 25rpx;
			padding: 36rpx 25rpx 0 25rpx;
		}

		.classification_item_4 {
			width: 338rpx;
			height: 281rpx;
			border-radius: 16rpx;
			background: url(/static/images/58.png) no-repeat;
			background-size: 100% 100%;
			margin-top: 25rpx;
			padding: 36rpx 25rpx 0 25rpx;
		}

		.classification_title {
			font-size: 35rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			color: #333333;
			margin-bottom: 7rpx;
		}

		.classification_tips {
			font-size: 20rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			color: #666666;
		}

		.classification_img {
			width: 136rpx;
			height: 136rpx;
			border-radius: 50%;
			margin: 6rpx 0 0 0;
			float: right;
		}

	}

	.yanjiang {
		padding: 0 25rpx;

		.yanjiang_img {
			width: 100%;
			height: 281rpx;
			// background: url(/static/images/21.png) no-repeat;
			background-repeat: no-repeat;
			background-size: 100% 100%;
			display: flex;
			justify-content: space-between;

			.yanjiang_left {
				padding: 50rpx 0 0 25rpx;
				display: flex;

				.yanjiang_left_img {
					width: 20rpx;
					height: 20rpx;
					margin-right: 20rpx;

					image {
						width: 100%;
						height: 100%;
					}
				}

				.yanjiang_left_content {
					.left_content_1 {
						font-size: 40rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: bold;
						color: #FFFFFF;
						margin-bottom: 5rpx;
					}

					.left_content_2 {
						font-size: 20rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						color: #FFFFFF;
						opacity: 0.5;
					}
				}
			}

			.yanjiang_right {
				padding: 40rpx 51rpx 0 0;

				image {
					width: 210rpx;
					height: 210rpx;
					border-radius: 50%;
				}
			}
		}
	}

	.home_title {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding-left: 25rpx;
		padding-right: 25rpx;
		padding-bottom: 26rpx;

		.text_text {
			font-size: 28rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			color: #333333;
		}

		.text_news {
			display: flex;
			align-items: center;

			.news_text {
				display: flex;
				align-items: center;
				justify-content: center;
				background: #FFFFFF;
				width: 91rpx;
				height: 35rpx;
				border-radius: 18rpx;
				font-size: 18rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				color: #333333;

				image {
					width: 19rpx;
					height: 19rpx;
					margin-right: 8rpx !important;
					margin-left: 0 !important;
				}
			}

			image {
				width: 40rpx;
				height: 40rpx;
				border-radius: 50%;
				margin-left: 25rpx;
			}
		}
	}

	.page {
		width: 100vw;
		overflow-x: hidden;
		min-height: calc(100vh - var(--window-bottom));
		background: var(--benbenbgColor1);
		background: url(/static/images/18.png) no-repeat;
		background-size: 100% 100% !important;
	}

	.index_flex_0 {
		width: 100%;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
	}

	.index_fd0_0_c2 {
		width: 48rpx;
		height: 48rpx;
	}

	.index_fd0_0_c0_c0 {
		width: 100%;
		height: 100%;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
	}

	.index_fd0_0_c0 {
		width: 203rpx;
		height: 56rpx;
	}

	.index_fd0_0 {
		padding: 0rpx 32rpx 0rpx 32rpx;
	}

	.index_flex_1 {

		height: 388rpx;
		background-size: 100% auto !important;
		padding: 0rpx 24rpx 0rpx 24rpx;
	}

	.index_fd1_0_c1 {
		margin: 0rpx 0rpx 0rpx 16rpx;
	}

	.index_fd1_0_c0 {
		width: 31rpx;
		height: 31rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
	}

	.index_fd1_0 {
		background: rgba(255, 255, 255, 1);
		margin: 24rpx 0rpx 0rpx 0rpx;
		border-radius: 34rpx 34rpx 34rpx 34rpx;
		padding: 18rpx 32rpx 18rpx 32rpx;
	}

	.index_flex_2 {
		margin: 0rpx 0rpx 0rpx 0rpx;
	}

	.index_numberfd2_0_c0 {
		background: #525050;
		position: absolute;
		bottom: 20rpx;
		right: 30rpx;
		width: 80rpx;
		height: 40rpx;
		border-radius: 6rpx 6rpx 6rpx 6rpx;
		font-size: 24rpx;
		color: #FFFFFF;
		line-height: 46rpx;
		font-weight: 400;
	}

	.index_fd2_0_c1_c0 {
		width: 100%;
		height: 100%;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
	}

	.index_fd2_0 {
		width: 702rpx;
		height: 300rpx;
	}

	.index_swiperDotUnselectedfd2_0 {
		border: 1px solid rgba(0, 0, 0, 0.3);
		background: var(--benbenbgColor1);
		width: 16rpx;
		height: 16rpx;
		border-radius: 100rpx 100rpx 100rpx 100rpx;
		margin: 0rpx 6rpx 0rpx 0rpx;
		font-size: 24rpx;
		color: #fff;
	}

	.index_swiperDotSelectedfd2_0 {
		background: var(--benbenbgColor1);
		width: 34rpx;
		height: 10rpx;
		border-radius: 100rpx 100rpx 100rpx 100rpx;
		margin: 0rpx 6rpx 0rpx 0rpx;
		font-size: 24rpx;
		color: #fff;
	}

	::v-deep .index_swiperDotfd2_0 {
		position: absolute;
		bottom: 20rpx;
		left: 0rpx;
		right: 0rpx;
	}

	.index_flex_3 {
		padding: 0rpx 24rpx 0rpx 24rpx;
		margin: 32rpx 0rpx 0rpx 0rpx;
	}

	.index_fd3_1_c1_c0 {
		width: 258rpx;
		height: 160rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
	}

	.index_fd3_1_c1 {
		margin: 0rpx 0rpx 0rpx 24rpx;
		border-radius: 16rpx;
	}

	.index_fd3_1_c0_c1 {
		color: #999999;
		font-size: 24rpx;
		font-weight: 400;
		line-height: 33rpx;
		margin: 47rpx 0rpx 0rpx 0rpx;
	}

	.index_fd3_1_c0_c0 {
		color: #333333;
		font-size: 28rpx;
		font-weight: 700;
		line-height: 40rpx;
		-webkit-line-clamp: 2;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
	}

	.index_fd3_1 {
		border-bottom: 1px solid #eee;
		padding: 32rpx 0rpx 32rpx 0rpx;
	}

	.index_fd3_0_c1 {
		margin: 0rpx 0rpx 0rpx 8rpx;
		color: #333333;
		font-size: 36rpx;
		font-weight: 700;
		line-height: 50rpx;
	}

	.index_fd3_0_c0 {
		width: 40rpx;
		height: 40rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
	}
</style>